package com.rc.saas.tenant.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * Create by Yang on 2021/9/17
 */
@Configuration //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class SimpleScheduleConfig {
    //3.添加定时任务
    //@Scheduled(cron = "0/10 * * * * ?")
    public void configureTasks1() {
        System.err.println("开始执行定时任务1: " + LocalDateTime.now());
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("执行定时任务1: " + LocalDateTime.now());
    }

    //3.添加定时任务
    //@Scheduled(cron = "0/10 * * * * ?")
    public void configureTasks2() {
        System.err.println("开始定时任务2: " + LocalDateTime.now());
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("执行定时任务2: " + LocalDateTime.now());
    }

    //3.添加定时任务
    //@Scheduled(cron = "0/10 * * * * ?")
    public void configureTasks3() {
        System.err.println("开始定时任务3: " + LocalDateTime.now());
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("执行定时任务3: " + LocalDateTime.now());
    }
}